/*
*Copyright 2021-2023 NERCIS
*
*Licensed under the Apache License, Version 2.0 (the "License");
*you may not use this file except in compliance with the License.
*You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*Unless required by applicable law or agreed to in writing, software
*distributed under the License is distributed on an "AS IS" BASIS,
*WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*See the License for the specific language governing permissions and
*limitations under the License.
*/

package cn.ac.nercis.pes.common.constant.evaluation;

import org.apache.commons.lang3.StringUtils;

import java.util.Arrays;
import java.util.List;
import java.util.Objects;

/**
 * 测评内容节点
 * @author zpy
 * @version 1.0.0
 */
public enum ContentNode {
    /**默认**/
    DEFAULT("","默认"),
    EVALUATION_BASIS("C1-2","测评依据"),
    BUSINESS_CONDITION("C2-1","承载的业务情况"),
    NETWORK_TOPOLOGY("C2-2","网络拓扑图及描述"),
    PASSWORD_CONDITION("C2-3","密码应用情况"),
    LAST_EVALUATION("C2-7","前次测评情况"),
    TOOL_CHECK_POINT("C3-2-3","测评工具检查点"),

    PREPARATION_PLAN_DETAIL("FA-C6-2-1","准备过程测评计划详情"),
    COMPILATION_PLAN_DETAIL("FA-C6-2-2","方案编制过程测评计划详情"),
    EVALUATION_PLAN_DETAIL("FA-C6-2-3","测评实施过程测评计划详情"),
    ANALYSIS_PLAN_DETAIL("FA-C6-2-4","分析与报告编制过程测评计划详情"),

    PROOF_DELEGATE("APPENDIX-B-1","密评委托证明"),
    PROOF_ACTIVITY("APPENDIX-B-2","密评活动证明"),
    PROOF_QUALITY("APPENDIX-B-3","密评活动质量文件"),
    PROOF_EVALUATOR("APPENDIX-B-4","密评人员资格证明文件"),
    PROOF_GRADING("APPENDIX-B-5","系统定级备案证明");

    private final String code;
    private final String name;

    ContentNode(String code, String name) {
        this.code = code;
        this.name = name;
    }

    public static ContentNode fromCode(String code){
        ContentNode data = DEFAULT;
        for(ContentNode cn :ContentNode.values()){
            if(StringUtils.equals(cn.code,code)){
                data = cn;
                break;
            }
        }
        return data;
    }

    public String getCode(){
        return this.code;
    }

    public String getName(){
        return this.name;
    }

    public static List<ContentNode> findProofNodes(){
        return Arrays.asList(PROOF_DELEGATE,PROOF_ACTIVITY,PROOF_QUALITY,PROOF_EVALUATOR,PROOF_GRADING);
    }

    public static List<ContentNode> findPrepareNodes(){
        var proofNodes = findProofNodes();
        return Arrays.stream(ContentNode.values())
                .filter(item->proofNodes.stream().noneMatch(n-> Objects.equals(item,n)))
                .toList();
    }

}